_Pragma("once");

//#include <unistd.h>
#include <fcntl.h>

#include "SerialPortCommunicator.h"
#include "StringUtility.h"

class SerialPortCommunicator485 : public SerialPortCommunicator {
public:
    SerialPortCommunicator485(const char* const deviceName = "/dev/ttymxc1") ;


    ssize_t write(const std::string& exceptionTip, void const * const data, const size_t size) noexcept {
        ssize_t returnlength;

        deviceFd = reopen();
        switchRs485(true);
        setPort(StringUtility::EMPTY_STRING);

        returnlength = ::write(deviceFd, data, size);
        closeFd(deviceFd);
        deviceFd = -1;

        return returnlength;
    }

     ssize_t read(const std::string& exceptionTip, void *buffer, const size_t length) noexcept ;


    /** Default destructor */
    virtual ~SerialPortCommunicator485();


protected:

    int mpollFd;
};
